﻿using System.Collections.Generic;
using System.Net.Sockets;
using System.Timers;
using CommunityToolkit.Mvvm.ComponentModel;
using Modbus.Device;

namespace AvaloniaApplicationDemo.Models;

public partial class DeviceModel : ObservableObject
{
    [ObservableProperty] private string? _deviceName;

    /// <summary>
    /// 主站配置
    /// </summary>
    [ObservableProperty] private ModbusMaster? _master;

    /// <summary>
    /// 连接状态
    /// </summary>
    [ObservableProperty] private bool _isConnected = false;

    /// <summary>
    /// TCP客户端
    /// </summary>
    [ObservableProperty] private TcpClient? _tcpClient;

    /// <summary>
    /// 图表数据定时器
    /// </summary>
    [ObservableProperty] private Timer _dataTimer;

    /// <summary>
    /// 设备数据映射表
    /// </summary>
    [ObservableProperty] private Dictionary<ushort, string> _registerMappings = new();

    public DeviceModel()
    {
    }

    public DeviceModel(string deviceName, ModbusMaster master, bool isConnected, TcpClient tcpClient,
        Dictionary<ushort, string> registerMappings)
    {
        DeviceName = deviceName;
        Master = master;
        IsConnected = isConnected;
        TcpClient = tcpClient;
        RegisterMappings = registerMappings;
    }
}